package com.xbdun.web.validatebmp.upload.core;

import java.util.Map;

import com.xbdun.facade.validatebmp.menus.UploadFileFormat;
import com.xbdun.web.validatebmp.upload.core.service.UploadFileReader;
import com.xbdun.web.validatebmp.upload.core.service.UploadOpenService;
/**
 * 上传文件读取工具类
 *
 */
public class UploadReadUtil {
	/**
	 * 载入上传文件Url
	 * @param uploadFileReader {@link UploadFileReader}
	 * @param uploadFileFormat {@link UploadFileFormat}
	 * @param uploadOpenService {@link UploadOpenService}
	 */
	public static <T> void loadUrl(UploadFileReader<T> uploadFileReader,UploadFileFormat uploadFileFormat,UploadOpenService uploadOpenService){
		long[] ids=new long[uploadFileReader.getDataList().size()];
		for(int i=0,j=uploadFileReader.getDataList().size();i<j;i++){
			Long uploadId=uploadFileReader.getUploadFileId(uploadFileReader.getDataList().get(i));
			if(null!=uploadId && uploadId>0){
				ids[i]=uploadId;
			}
		}
		Map<Long,String> result=uploadOpenService.getUrlsMap(uploadFileFormat, ids);
		for(T data:uploadFileReader.getDataList()){
			Long uploadId=uploadFileReader.getUploadFileId(data);
			uploadFileReader.setReadUrl(data, result.get(uploadId));
		}
	}
	private UploadReadUtil() {
		// TODO Auto-generated constructor stub
	}

}
